{{if false}}<script>{{/if}}
Array.prototype.in_array = function(p_val) {
	for(var i = 0, l = this.length; i < l; i++) {
		if(this[i] == p_val) {
			return true;
		}
	}
	return false;
}
function includejs(url){ 
    document.write( '<script type="text\/javascript" src="'+ url +'"><\/script>' ); 
}
function includecss(url){ 
    document.write( '<link type="text\/css" href="'+ url +'"rel="stylesheet" media="all" title="style" \/>' ); 
}
function _includejs(url){ 
    var _ui = document.createElement('script'); 
    _ui.type = 'text/javascript';
    _ui.src = url;
    var s = document.getElementsByTagName('script')[0]; 
    s.parentNode.insertBefore(_ui, s);
}
function _includecss(url){ 
    var _ui = document.createElement('link'); 
    _ui.rel = 'stylesheet';
    _ui.type = 'text/javascript';
    _ui.href = url;
    var s = document.getElementsByTagName('link')[0]; 
    s.parentNode.insertBefore(_ui, s);
}
function ShowLoadding(){
    $("#myloadding").show();
    $("#myloadding div").stop(true).width(0).css({
        bottom:1
    })
    .animate({
        width:'30%'
    },500)
    .animate({
        width:'50%'
    },1000)
    .animate({
        width:'75%'
    },2000)
    .animate({
        width:'95%'
    },5000);
}
function HideLoadding(){
    $("#myloadding div").stop(true)
    .animate({
        width:'100%'
    },1000,function(){
        $("#myloadding").hide();
    });
        
        
}
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
function CloseConfirmDialogMessage(confirm){
    if(typeof(confirm)=="object"){
        confirm.dialog( "close" );
    }else{
        $( "#confirm-dialog-message" ).dialog( "close" );
    }
}
function OpenConfirmDialogMessage(confirm){
    if(typeof(confirm)=="object"){
        confirm.dialog( "open" );
    }else if(typeof(confirm)=="string"){
        $( "#confirm-dialog-message" ).dialog( "open" );
    }
}
function ShowConfirmDialogMessage( confirm ,title, callback ){
    var obj;
    if(typeof(confirm)=="object"){
        obj=confirm;
    }else if(typeof(confirm)=="string"){
        obj=$( "#confirm-dialog-message" );
        //obj.dialog( "destroy" );
        obj.html( confirm );
    }
        
        
    //$( "#confirm-dialog-message" ).attr("title", title );
    //$( "#confirm-dialog-message" ).dialog( 'open' );
        
    obj.dialog({
        resizable   : false,
        minwidth      :240,
        width      :'auto',
        modal       : true,
        bgiframe: true,
        //hide        : "explode",
        title: "<img style='position:absolute;top:7px;left:8px' src='{{base_url()}}syslib/jquery-ui-1.9.2/themes/base/images/dialog_warning.png'/><font style='padding-left:20px;'>"+(title==undefined?"Comfirm Message !":title)+"</font>",
        buttons: {
            Ok: function() {
                //$( this ).dialog( "close" );
                if (callback && typeof(callback) === "function") { 
                    try{
                        callback();           
                    }catch(e){

                    }
                }
            }
            ,
            Cancel: function() {
                $( this ).dialog( "close" );
            }
        }
    });              
                 
}
function ShowErrorDialogMessage( error_message , callback ){
    var obj;
    if(typeof(error_message)=="object"){
        obj=error_message;
    }else if(typeof(error_message)=="string"){
        obj=$( "#error-dialog-message" );
        //obj.dialog( "destroy" );
        obj.html( error_message );
    }
        
    obj.dialog({
        modal: true,
        //autoOpen            : false,
        resizable   : false,
        minwidth      :240,
        width      :'auto',
        closeOnEscape       : false,
        //hide                : "explode",
        buttons: {
        //                Ok: function() {
        //                    $( this ).dialog( "close" );
        //                }
        },
        title: "<img style='position:absolute;top:7px;left:8px' src='{{base_url()}}syslib/jquery-ui-1.9.2/themes/base/images/dialog_error.png'/><font style='padding-left:20px;color:red'>Error Message !</font>",
        close: function(event, ui) { 
            if (callback && typeof(callback) === "function") { 
                try{
                    callback();           
                }catch(e){

                }
            } 
        }
    });              
            
         
}
function ShowNoticeDialogMessage( notice_message ,title, callback ){
    var obj;
    if(typeof(notice_message)=="object"){
        obj=notice_message;
    }else if(typeof(notice_message)=="string"){
        obj=$( "#notice-dialog-message" );
        //obj.dialog( "destroy" );
        obj.html( notice_message );
    }
    obj.dialog({
        modal: true,
        //autoOpen            : false,
        minwidth      :'320px',
        resizable: false,
        width      :'auto',
        title: "<img style='position:absolute;top:7px;left:8px' src='{{base_url()}}syslib/jquery-ui-1.9.2/themes/base/images/dialog_warning.png'/><font style='padding-left:20px;'>"+(title==undefined?"Notice Message !":title)+"</font>",
        closeOnEscape       : false,
        //hide                : "explode",
        buttons: {
        },
        close: function(event, ui) { 
            if (callback && typeof(callback) === "function") { 
                try{
                    callback();           
                }catch(e){

                }
            } 
        }
    });             
}
function ShowDialogMessage( notice_message ,title, callback ){
    var obj;
    if(typeof(notice_message)=="object"){
        obj=notice_message;
    }else if(typeof(notice_message)=="string"){
        obj=$( "#notice-dialog-message" );
        //obj.dialog( "destroy" );
        obj.html( notice_message );
    }
    obj.dialog({
        modal: true,
        //autoOpen            : false,
        minwidth      :'320px',
        resizable: false,
        width      :'auto',
        title: ( title == undefined ? "Thông báo !" : title ),
        closeOnEscape       : false,
        //hide                : "explode",
        buttons: {
        },
        close: function(event, ui) { 
            if (callback && typeof(callback) === "function") { 
                try{
                    callback();           
                }catch(e){

                }
            } 
        }
    });             
}
function untip(){
    $("#tipMessage").stop().hide();
}
function stoptip(){
    $("#tipMessage").stop().css({opacity:1}).fadeIn();
}
function tipMessage(msg,auto){
        
    if($("#tipMessage").length==0 || typeof($("#tipMessage")) == 'undefined' || $("#tipMessage") == null || $("#tipMessage") == undefined){
        $('body').append('<div onmouseover="stoptip()" id="tipMessage" class="tip-green" style="visibility: inherit; left: 360px; top: 36px; opacity: 1;position: fixed;z-index:2002">\
                <div class="tip-inner tip-bg-image tipcontent">Loadding...</div>\
                <div class="tip-arrow tip-arrow-bottom" style="visibility: inherit;position: absolute"></div>\
                <div class="tip-close" onclick="untip()"></div>\
            </div>');
    }
    $("#tipMessage .tipcontent").html(msg);
    if(auto==undefined){
        $("#tipMessage").stop().fadeIn().delay(5000).fadeOut();
    }else{
        $("#tipMessage").stop().fadeIn();
    }
}
function untipui(){
    $("#uiMessage").stop().hide();
}
function stoptipui(){
    $("#uiMessage").stop().css({display:"block",opacity:1});
}
function uiMessage(msg,auto){
        
    if($("#uiMessage").length==0 || typeof($("#uiMessage")) == 'undefined' || $("#uiMessage") == null || $("#uiMessage") == undefined){
        $('body').append('<div id="uiMessage" onmouseover="stoptipui()" class="hparent tranf10 ui-corner-all hidden" style="position: fixed; left: 150px; top: 36px; padding: 8px;z-index: 99999">\
    <div class="ui-dialog-content ui-widget-content pt8 pb8 pl8 pr8 ovfh ovfxa" style="max-width: 600px;" > \
    </div>\
    <div class="jfk-bubble-closebtn hchild" onclick="untipui()" style=""></div>\
</div>');
    }
    $("#uiMessage .ui-dialog-content").html(msg);
    if(auto==undefined){
        $("#uiMessage").stop().fadeIn().delay(5000).fadeOut();
    }else{
        $("#uiMessage").stop().hide().fadeIn();
    }
}

function myAjax(surl,odata,callback){
    isrunning=true;
    ShowLoadding();
    jQuery.ajax({
        type:"POST", 
        data:odata, 
        dataType:"text", 
        url:surl, 
        success: function (data){
            isrunning=false;
            HideLoadding(); 
            try{
                    
                var result=JSON.parse(data);
                    
                if (callback && typeof(callback) === "function") { 
                    try{
                        callback(result);  
                    }catch(e){
                        console.log("Error:"+e.message+"\nContent:"+data+"\n↵ Error");
                        ShowErrorDialogMessage(e.message);
                    }
                } 
            }catch(e){
                console.log("JSON Error:"+e.message+"\nContent:"+data+"\n↵ Error");
                ShowErrorDialogMessage("<pre>JSON Error:"+e.message+"\nContent:\n"+data+"</pre>");
            }
        },
        error: function (xhr, ajaxOptions, thrownError){
            console.log("Status:"+xhr.status+"\nThrownError:"+thrownError+"\nURL:"+surl+"\n↵ Error");
            isrunning=false;
            HideLoadding();
            ShowErrorDialogMessage("Sorry. Your request could not be completed.<br/> Please check your input data.");
            
        }
    });
}
function htmlAjax(surl,sdata,obj,callback){
    isrunning=true;
    ShowLoadding();
    jQuery.ajax({
        type:"POST", 
        data:sdata, 
        dataType:"text", 
        url:surl, 
        success: function (data){
            isrunning=false;
            HideLoadding(); 
            try{
                if(typeof(obj)=="object"){

                }else if(typeof($(obj))=="object"){
                    obj=$(obj);
                }else{
                    console.log("Sorry. Element not found.\n↵ Error");
                    tipMessage("Sorry. Element not found.");
                    return;
                }
                obj.html(data);
                if (callback && typeof(callback) === "function") {  
                    callback();  
                }
            }catch(e){
                console.log("Error:"+e.message+"\nContent:"+data+"\n↵ Error");
                ShowErrorDialogMessage("<pre>Error:"+e.message+"\nContent:"+data+"</pre>");
            }
        },
        error: function (xhr, ajaxOptions, thrownError){
            console.log("Status:"+xhr.status+"\nThrownError:"+thrownError+"\nURL:"+surl+"\n↵ Error");
            isrunning=false;
            HideLoadding(); 
            ShowErrorDialogMessage("Sorry. Your request could not be completed.<br/> Please check your input data.");
        }
    });
}
function BrowseServer( _objid )
{
    try{
        window.KCFinder = {};
        window.KCFinder.callBack = function(url) { 
            window.KCFinder = null;
            $('#'+_objid).val(url);
            console.log(url);
        };
        window.open( baseurl+'syslib/kcfinder/browse.php?lang=vi', 'kcfinder_textbox',
            'status=0, toolbar=0, location=0, menubar=0, directories=0, resizable=1, scrollbars=0, width=700, height=500'
            );
    }catch(e){
        console.log("JSON Error:"+e.message+"\n↵ Error");
        ShowErrorDialogMessage(e.message);
    }
}
function hideparent(t){
    $(t).parent().hide(500);
}
function tab(){
    
}
function chkb(chk){
    $(chk).toggleClass("cked");
}
function rdbck(rdb){
    if($(rdb).attr("group"))
        $(".radio.cked[group='"+$(rdb).attr("group")+"']").removeClass("cked");
    else
        $(".radio.cked").removeClass("cked");
    $(rdb).addClass("cked");
            
}
function s_m_b(obj){
    $(obj).parent().find(".more-box").show();
}

    function getAliasTo(from,to){
        try{
            if($(from).val()=="")return;
			if($(from).val()==$(from+'c').val())return;
            var url=baseurl+"sys/excution/getAlias";
            var data={
                string:$(from).val()
            };
            myAjax(url,data,function(result){
                isrunning=false;
                if(result.code>=0){
                    $(to).val(result.msg);
					$(from+'c').val($(from).val());
                }else{
                    tipMessage(result.msg);
				}
            });
        }catch(e){ ShowErrorDialogMessage(e.message); }
    }
    function GenAlbumItemFromContent(Content,AlbumItems){
        var AlbumItems =$(AlbumItems);
        $(Content+" img").each(function(){
            var srcImg=$(this).attr("src");
            var AlbumItem=
            '<div class="AlbumItem grid_5 mb4 mt4 ml4 mr4 bdccc gadiend-white">\
                <div class="pt1 pb1 pl1 pr1">\
                    <div class="pl8 pt4 pb4 pr8 ovfh mt0 mb0 mr0 ml0 bdbccc">\
                        Album item\
                    </div>\
                    <div class="pa r8 t4">\
                        <span class="hover50" style="cursor: pointer" onclick="DelAlbumItem(this)">✖</span>\
                    </div>\
                    <div class="pl4 pr4 pt4 pb4 mt0 mb0 ml0 mr0 ovfa pr" style="height: 220px">\
                        <img src="'+srcImg+'"/>\
                    </div>\
                </div>\
            </div>';
            AlbumItems.append(AlbumItem);
        });
    }
    function addRedactorEditor(Element){
        Element.redactor({
            //air: true,
            //wym: true,
            buttons: ['html','formatting', '|', 'bold', 'italic', 'deleted', '|','unorderedlist','orderedlist','outdent','indent','alignment','|','video','link','|','fontcolor','backcolor']
            ,plugins: ['advanced']
        });
    }
    function addEditorContent(ElementID){
        try{
        tinyMCE.init({
                // General options
                mode : "exact",
                elements : ElementID,
                theme : "advanced",
                //skin : "o2k7",
                plugins : "safari,pagebreak,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,media,paste,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
                height :500,
                width : "100%",
                // Theme options
                theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,outdent,indent,blockquote,|,fontselect,fontsizeselect",
                theme_advanced_buttons2 : "forecolor,backcolor,|,link,image,|,hr,sub,sup,emotions,iespell,media,|,removeformat,visualaid,cleanup,code,fullscreen",
                theme_advanced_buttons3 : "",
                theme_advanced_buttons4 : "",
                theme_advanced_toolbar_location : "top",
                theme_advanced_toolbar_align : "left",
                theme_advanced_statusbar_location : "bottom",
                //theme_advanced_resizing : true,

                // Example content CSS (should be your site CSS)
                //content_css : "css/example.css",

                // Drop lists for link/image/media/template dialogs
                //template_external_list_url : "js/template_list.js",
                //external_link_list_url : "js/link_list.js",
                //external_image_list_url : "js/image_list.js",
                //media_external_list_url : "js/media_list.js",

                file_browser_callback: 'openKCFinder'
        });
        }catch(e){ ShowErrorDialogMessage(e.message); }
    }
    function openKCFinder(field_name, url, type, win) {
        tinyMCE.activeEditor.windowManager.open({
            file: '{{base_url()}}syslib/kcfinder/browse.php?opener=tinymce&type=' + type,
            title: 'KCFinder',
            width: 700,
            height: 500,
            resizable: "yes",
            inline: true,
            close_previous: "no",
            popup_css: false
        }, {
            window: win,
            input: field_name
        });
        return false;
    }
    function updateCol(token,control,col,_id,_value){
        var url,data;
        url="{{base_url()}}backend/fe548e5a964095e7c80cd8d3721be2ef/columnUpdate/"+token+"/"+control+"/"+col;
        data={
            _id      :   _id,
            _value   :   _value
        }
        isrunning=true;
        myAjax(url,data,function(result){
            isrunning=false;
            if(result.code>=0){
                tipMessage(result.msg);
                //ShowNoticeDialogMessage(result.msg);
            }else{
                ShowErrorDialogMessage(result.msg);
                //ShowNoticeDialogMessage(result.msg);
            }
        });
    }
    function uitooltip(){
        $(document).tooltip({
            track: true,
            position: {
                my: "center top+20",
                at: "center bottom-20"
            }
        });
    }
    function _whyerror(){
        uiMessage("<pre>Dữ liệu không thêm được vào <tt>Database</tt> trong các trường hợp sau\n\
    ✓ dữ liệu dị thường: sử dụng các ký tự đặc biệt, các từ bị cấm sử dụng, các từ liên quan đến hệ thống\n\
    ✓ dữ liệu bị trùng lặp, ví dụ như trùng <tt>tên</tt>, trùng <tt>alias</tt> hoặc trùng các thuộc tính có đặc điểm là duy nhất\n\
    ✓ lỗi hệ thống, lỗi mạng...\n\
Vui lòng kiểm tra kỹ thông tin dữ liệu đầu vào, và thử lại.\
        </pre>",false);
    }
    function ChangeMyPassWord(){
        ShowConfirmDialogMessage($("#frmchangemypassword"), "Change your Secret Key", function(){
            if(isrunning) return;
            if(!_FcheckFilled($("#txtcurrentpassword").val())){
                $("#txtcurrentpassword").focus();
                return;
            }
            if(!_FcheckFilled($("#txtnewpassword").val())){
                $("#txtnewpassword").focus();
                return;
            }
            var url = "{{base_url()}}OAuth/home/changepassword/940cc81cec5c7e119162e62bd57710f0"
            var data={
                currentpass : $("#txtcurrentpassword").val(),
                newpass : $("#txtnewpassword").val()
            }
            isrunning=true;
            myAjax(url,data,function(result){
                isrunning=false;
                try{
                    if(result.code<0){
                        ShowErrorDialogMessage(result.msg);
                    }else{
                        CloseConfirmDialogMessage($("#frmchangemypassword"));
                        ShowNoticeDialogMessage(result.msg);
                    }
                }catch(e){                                    
                    ShowErrorDialogMessage(e.message);
                }
            });
        });
    }
{{if false}}</script>{{/if}}